package com.wmyg.antifake.service.impl;

import com.wmyg.antifake.entity.BkUser;
import com.wmyg.antifake.entity.Company;
import com.wmyg.antifake.repository.BkUserRepository;
import com.wmyg.antifake.repository.CompanyRepository;
import com.wmyg.antifake.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-20
 */
@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    BkUserRepository bkUserRepository;

    @Autowired
    CompanyRepository companyRepository;

    @Override
    public Boolean save(Company company, String username) {
        BkUser bkUser = bkUserRepository.findByUsername(username);
        if (null != bkUser) {
            bkUser.setCompany(company);
            bkUser.setAuditState(1);
            bkUserRepository.save(bkUser);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Boolean save(Company company) {
        Company companyOld = companyRepository.findByCompanyId(company.getCompanyId());
        if (null != companyOld) {
            company.setCreateTime(companyOld.getCreateTime());
        }
        companyRepository.save(company);
        return true;
    }
}
